/*******************************************************************************
 File Name        : freyabaseaction.h
 Summary          : Base class of asynchronous message processing
 Create           : 2015-04-27
 Author           : Schindleren
 Update history   :
 NO.     Author        Date         Content
 001     Schindleren   2015-04-27   Create New
 002     Schindleren   2020-08-14   remove synchronous interface
*******************************************************************************/
#ifndef FREYABASEACTION_H
#define FREYABASEACTION_H

#include "freyalib_global.h"
#include "freyabasecontrol.h"
#include "freyaabstractaction.h"
#include "freyaactiondataq.h"

#include <QMutex>
#include <QMutexLocker>

// FREYALIB_CMD_CMDREGREQUEST == 0x0000000070000000ULL //FreyaLib_Cmd_CommandRegisterRequest

#define FREYACONNECT(cmd, func)    if(cmd == pData->command) \
                                   { func; return; } \
                                   else if(FREYALIB_CMD_CMDREGREQUEST == pData->command) \
                                   { m_CommandList.append(cmd); }

class FREYALIBSHARED_EXPORT FreyaBaseAction : public FreyaAbstractAction
{
public:
    explicit FreyaBaseAction(FreyaBaseControl *pControl = nullptr, const char *actionName = nullptr, bool bIsAsync = true, int cachesize = 10);
    virtual ~FreyaBaseAction();
    void *FreyaRequester(){return m_FreyaBaseControl->FreyaRequester();}

    QString ActionName();

    /***************************************************
      Author: Schindleren
      Date: 2015-04-27
      Description: Execute with no arguments
                    rewrite this funcation to execute actions
      Input: void
      Output: void
      Return: void
    ****************************************************/
    virtual void Execute(){}

    /***************************************************
      Author: Schindleren
      Date: 2015-04-27
      Description: Execute with FreyaData
                    rewrite this funcation to execute actions
                    If called RegisterCommands(), FreyaControl while only Execute connected command.
                    If Connected none command, RegisterCommands() is no used.
      Input: FreyaData
      Output: void
      Return: void
    ****************************************************/
    virtual void Execute(const FreyaData /*pData*/){}

    void ExecuteCache(const FreyaData pData);

protected:
    /***************************************************
      Author: Schindleren
      Date: 2015-04-27
      Description: register commands
                    If Connected none command, RegisterCommands() is no used.
      Input: void
      Output: void
      Return: void
    ****************************************************/
    virtual void RegisterCommands();

protected:
    FreyaBaseControl    *m_FreyaBaseControl;
    QList<quint64>      m_CommandList;
    QString             m_ActionName;

private:
    FreyaActionDataQ    *m_pFreyaActionDataQ;
};

#endif // FREYABASEACTION_H
